API: Add gdk_texture_new_from_filename()
authorBenjamin Otte <otte@redhat.com>
Wed, 15 Sep 2021 20:08:33 +0000 (22:08 +0200)
committerBenjamin Otte <otte@redhat.com>
Thu, 16 Sep 2021 21:59:37 +0000 (23:59 +0200)
There are quite a few places where we can make use of it, in particular
in the testsuite and icontheme.

gdk/gdktexture.c
gdk/gdktexture.h

index edcf7a9d9c6f0de8a99e3748f1921418dddda0fa..ec03c723707ce9660702bfadbff974491f93e740 100644 (file)
@@ -441,6 +441,39 @@ gdk_texture_new_from_bytes (GBytes  *bytes,
   return texture;
 }
 
+/**
+ * gdk_texture_new_from_filename:
+ * @path: (type filename): the filename to load
+ * @error: Return location for an error
+ *
+ * Creates a new texture by loading an image from a file.
+ *
+ * The file format is detected automatically. The supported formats
+ * are PNG and JPEG, though more formats might be available.
+ *
+ * If %NULL is returned, then @error will be set.
+ *
+ * Return value: A newly-created `GdkTexture`
+ */
+GdkTexture *
+gdk_texture_new_from_filename (const char  *path,
+                               GError     **error)
+{
+  GdkTexture *texture;
+  GFile *file;
+
+  g_return_val_if_fail (path, NULL);
+  g_return_val_if_fail (error == NULL || *error == NULL, NULL);
+
+  file = g_file_new_for_path (path);
+
+  texture = gdk_texture_new_from_file (file, error);
+
+  g_object_unref (file);
+
+  return texture;
+}
+
 /**
  * gdk_texture_get_width: (attributes org.gtk.Method.get_property=width)
  * @texture: a `GdkTexture`
index 7cccdb592831e8b5542580bb55cd8c7988d5214e..e080679ca178ab48d8944104dccc91b2a709e154 100644 (file)
@@ -50,6 +50,9 @@ GDK_AVAILABLE_IN_ALL
 GdkTexture *            gdk_texture_new_from_file              (GFile           *file,
                                                                 GError         **error);
 GDK_AVAILABLE_IN_4_6
+GdkTexture *            gdk_texture_new_from_filename          (const char      *path,
+                                                                GError         **error);
+GDK_AVAILABLE_IN_4_6
 GdkTexture *            gdk_texture_new_from_bytes             (GBytes          *bytes,
                                                                 GError         **error);